﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;
using CI.Models.Data;
using CI.Models.Production;
using CI.Models.Production.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CI.Models.Tests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class FormulaTests
    {
        [TestMethod]
        public void MaterialEfficienyResearch_BloodclawLightMissile_Amminous_EVE_Comparison()
        {
            Assert.AreEqual(5100, ManufacturingFormula.MaterialEfficienyResearch(6000, 3, null, null));
        }

        [TestMethod]
        public void MaterialEfficienyResearch_Providence_Amminous_EVE_Comparison()
        {
            Assert.AreEqual(4352000, ManufacturingFormula.MaterialEfficienyResearch(5120000, 3, null, null));
        }


        [TestMethod]
        public void ProductionTime_Providence_Amminous_EVE_Comparison()
        {
            var providence = ProductionRepo.Get(20183);

            Assert.AreEqual(1126400,
                            ManufacturingFormula.ProductionTime(3, null, null, 0,
                                                   providence.Blueprint.ProductivityModifier, providence.Blueprint.ProductionTime));
        }

        public static IStaticDataRepository<Item> ProductionRepo { get; set; }

        [TestInitialize]
        public void Load()
        {
            ProductionRepo = new XmlDataRepository<Item>("Production.xml");
            ProductionRepo.Load();
        }

        [TestMethod]
        public void ProductionTime_BloodclawLightMissile_Amminous_EVE_Comparison()
        {
            var missile = ProductionRepo.Get(210);

            Assert.AreEqual(264,
                            ManufacturingFormula.ProductionTime(3, null, null, 0,
                                                   missile.Blueprint.ProductivityModifier, missile.Blueprint.ProductionTime));
        }

        [TestMethod]
        public void MaterialCost_BloodclawLightMissile_Amminous_EVE_Comparison()
        {
            var missile = ProductionRepo.Get(210);

            CheckMaterialCost(74, missile, "Tritanium");
            CheckMaterialCost(47, missile, "Pyerite");
            CheckMaterialCost(2, missile, "Mexallon");
        }

        [TestMethod]
        public void MaterialCost_Raven_Amminous_EVE_Comparison()
        {
            var raven = ProductionRepo.Get(638);

            CheckMaterialCost(9093158, raven, "Tritanium");
            CheckMaterialCost(2273762, raven, "Pyerite");
            CheckMaterialCost(35514, raven, "Nocxium");
            CheckMaterialCost(569610, raven, "Mexallon");
            CheckMaterialCost(2705, raven, "Megacyte");
            CheckMaterialCost(142223, raven, "Isogen");
            CheckMaterialCost(8472, raven, "Zydrine");
        }

        private static void CheckMaterialCost(decimal expected, Item item, string material)
        {
            var materialType = ProductionRepo.All.Where(m => m.TypeName == material).FirstOrDefault();
            var materials = item.Materials;
            //var bq = materials

            var bq = (int)materials.Where(a => a.MaterialTypeID == materialType.TypeID).FirstOrDefault().Quantity;
            var wf = (int) item.Blueprint.WasteFactor;

                Assert.AreEqual(expected,
                                ManufacturingFormula.MaterialCost(bq
                                    , wf, 0, 3));
        }
    }
}